package com.duck.user.controller;

import com.duck.common.domain.Result;
import com.duck.common.utils.UserContext;
import com.duck.user.domain.po.UserPojo;
import com.duck.user.domain.vo.AutorInfoVo;
import com.duck.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;

@RestController
@RequestMapping("/user")
public class GetUserInfoController {

    @Autowired
    private UserService userService;

    /**
     * 查看用户个人信息
     * @return 用户个人信息
     */
    @PostMapping("/getUserInfo/")
    public Result getUserInfo(){
        //获取用户ID
        System.out.println(UserContext.getUser());
        String userId = String.valueOf(UserContext.getUser());
        //根据id获得该用户
        UserPojo user = userService.getUserByUserId(userId);
//        List<HashMap<String,Object>> userInfo = new ArrayList<>();
//        HashMap<String,Object> info = new HashMap<>(){{
//            put("avatar",user.getAvatar());
//            put("username",user.getUsername());
//            put("user_type",user.getUserType());
//            put("email",user.getEmail());
//
//        }};
//        userInfo.add(info);
        return new Result(user,200,"成功");
    }

//    @PostMapping("/getUserRole/")
//    @PreAuthorize("hasAuthority('public_permission')")
//    public Result getUserRole(HttpServletRequest request){
//        //获取用户ID
//        String userId = getTokenInfo.getUserIdByJwt(request);
//        String data = userService.getUserRole(userId);
//        return new Result(data,200,"成功");
//    }
    @GetMapping("/searchExpert/")
    public Result searchExpert(){
        List<HashMap<String,Object>> userPojo=userService.searchExpert();
        return new Result(userPojo,200,"成功");
    }

    @GetMapping("/AutorInfo/")
    public Result AutorInfo(@RequestParam String userId){
        String currentUserId = String.valueOf(UserContext.getUser());
        AutorInfoVo autorInfoVo = userService.searchAutorInfo(userId,currentUserId);
        return new Result(autorInfoVo,200,"成功");
    }
}
